<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleleaf.org">
<head th:insert="base">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="/back/welcome">首页</a>
            <a href="#">检修任务管理</a>
            <a>
              <cite>检修任务列表（监管员）</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <div class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" id="switchCode"  placeholder="请输入道岔编号" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select id="repairmanAccount">
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select id="repairLevel">
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select id="taskType">
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" readonly  autocomplete="off" placeholder="截止开始日期" id="closeTimeStart">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" readonly  autocomplete="off" placeholder="截止截止日期" id="closeTimeEnd">
                        </div>
                        <br/>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" readonly  autocomplete="off" placeholder="完成开始日期" id="finishTimeStart">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" readonly  autocomplete="off" placeholder="完成截止日期" id="finishTimeEnd">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" id="formSearch"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-hide" id="tableId" lay-filter="tableId"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加</button>
    </div>
</script>
<script type="text/html" id="operations">
    <a class="layui-btn layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" title="删除"><i class="layui-icon layui-icon-delete"></i>删除</a>
    {{#if(d.taskType == '1'){}}
        <a class="layui-btn layui-btn-xs" lay-event="unQualified" title="检修不合格"><i class="layui-icon layui-icon-tread"></i>检修不合格</a>
        <a class="layui-btn layui-btn-xs" lay-event="qualified" title="检修合格"><i class="layui-icon layui-icon-praise"></i>检修合格</a>
    {{#}}}
    {{#if(d.taskType == '3' || d.taskType == '4'){}}
    <a class="layui-btn layui-btn-xs" lay-event="rePub" title="重新发布"><i class="layui-icon layui-icon-edit"></i>重新发布</a>
    {{#}}}
    <a class="layui-btn layui-btn-xs" lay-event="record" title="记录检修记录"><i class="layui-icon layui-icon-survey"></i>记录检修记录</a>
</script>
<script th:inline="none">
    layui.use(['table','form','util','tool','laydate','enums','businessUtil'], function(){
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var util = layui.util;
        var tool = layui.tool;
        var laydate = layui.laydate;
        var baseUrl = "/back/repairTask";
        var businessUtil = layui.businessUtil;
        var enums = layui.enums;
        init_form();
        table.render({
            elem: '#tableId'
            ,id:'tableReload'
            ,url: baseUrl + '/getSupervisorList'
            ,limit:10
            ,limits:[10,20,50]
            ,method:'post'
            ,toolbar:'#toolbar'
            ,defaultToolbar: ['print']
            ,title: '检修任务列表'
            ,cols: [[
                {field: '', title: '序号',width:50,type:'numbers'}
                ,{field:'switchCode', title:'道岔编号',type: 'text',width:200}
                ,{field:'repairPlaceDesc', title:'检修部位',type: 'text',width:200}
                ,{field:'repairLevelDesc', title:'检修级别',type: 'text',width:200}
                ,{field:'taskTypeDesc', title:'任务状态',type: 'text',width:200}
                ,{field:'supervisorName', title:'监管员',type: 'text',width:150}
                ,{field:'repairmanName', title:'维修员',type: 'text',width:150}
                ,{field:'remark', title:'备注',type: 'text',width:400}
                ,{field:'createTime', title:'截止时间',type: 'text',width:160,templet:function (d) {
                        if(d.closeTime){
                            return util.toDateString(d.closeTime, "yyyy-MM-dd HH:mm:ss")
                        }
                        return "";
                    }}
                ,{field:'createTime', title:'完成时间',type: 'text',width:160,templet:function (d) {
                        if(d.finishTime){
                            return util.toDateString(d.finishTime, "yyyy-MM-dd HH:mm:ss")
                        }
                        return "";
                    }}
                ,{field:'createTime', title:'创建时间',type: 'text',width:160,templet:function (d) {
                        if(d.createTime){
                            return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss")
                        }
                        return "";
                    }}
                ,{title:'操作', toolbar: '#operations',width:500}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(tableId)', function(obj){
            switch(obj.event){
                case 'add':
                    xadmin.open('添加检修任务信息',baseUrl + '/add');
                    break;
            };
        });
        //行工具栏事件
        table.on('tool(tableId)', function(obj){
            var data = obj.data;
            switch (obj.event) {
                case 'edit':
                    xadmin.open('编辑检修任务信息',baseUrl + '/edit?id='+data.id);
                    break;
                case 'record':
                    xadmin.open('记录检修记录','/back/repairRecord/add?repairId='+data.id,800,300);
                    break;
                case 'rePub':
                    layer.confirm('确认重新发布此信息？', function(index){
                        var res = tool.submit(baseUrl + '/rePub',{id:data.id});
                        if(res.code == return_200){
                            layer.msg(res.msg, {
                                    icon: msg.success,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }else {
                            layer.msg(res.msg, {
                                    icon: msg.error,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }
                    });
                    break;
                case 'unQualified':
                    layer.confirm('确认检修不合格？', function(index){
                        var res = tool.submit(baseUrl + '/unQualified',{id:data.id});
                        if(res.code == return_200){
                            layer.msg(res.msg, {
                                    icon: msg.success,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }else {
                            layer.msg(res.msg, {
                                    icon: msg.error,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }
                    });
                    break;
                case 'qualified':
                    layer.confirm('确认检修合格？', function(index){
                        var res = tool.submit(baseUrl + '/qualified',{id:data.id});
                        if(res.code == return_200){
                            layer.msg(res.msg, {
                                    icon: msg.success,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }else {
                            layer.msg(res.msg, {
                                    icon: msg.error,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }
                    });
                    break;
                case 'del':
                    layer.confirm('确认删除此信息？', function(index){
                        var res = tool.submit(baseUrl + '/delete',{id:data.id});
                        if(res.code == return_200){
                            layer.msg(res.msg, {
                                    icon: msg.success,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }else {
                            layer.msg(res.msg, {
                                    icon: msg.error,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }
                    });
                    break;
            }
        });
        //条件查询
        $('#formSearch').on('click', function(){
            table.reload('tableReload', {
                page: {curr: 1 }
                ,where:  getQueryParams()
            });
        });

        /**
         * 查询的参数
         * @returns {{}}
         */
        function getQueryParams() {
            return {
                switchCode:$("#switchCode").val().trim()
                ,repairmanAccount:$("#repairmanAccount").val().trim()
                ,repairLevel:$("#repairLevel").val().trim()
                ,taskType:$("#taskType").val().trim()
                ,closeTimeStart:$("#closeTimeStart").val().trim()
                ,closeTimeEnd:$("#closeTimeEnd").val().trim()
                ,finishTimeStart:$("#finishTimeStart").val().trim()
                ,finishTimeEnd:$("#finishTimeEnd").val().trim()
            }
        }

        /**
         * 初始化页面
         */
        function init_form() {
            enums.createSelectByEnum('taskType','EnumRepairType',null,null,'请选择任务状态');
            enums.createSelectByEnum('repairLevel','EnumRepairLevel',null,null,'请选择检修级别');
            businessUtil.createUserInfo('repairmanAccount','repairman',null,'请选择维修员');
            form.render();//重新渲染
            laydate.render({
                elem: '#closeTimeStart'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#closeTimeEnd'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#finishTimeStart'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#finishTimeEnd'
                ,type: 'datetime'
            });
        }

        /**
         * 回调函数
         */
        function callBack() {
            $("#formSearch").click();
        }


    });
</script>
</body>
</html>